package com.hq.fxh.No2_BBS.Activity;

import android.content.Intent;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hq.fxh.No2_BBS.Fragment.PlateSortDetailFragment;
import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.R;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.Tool;

import java.util.ArrayList;


public class PlateDetialActivity extends BaseActivity {


    public ImageView imagePlateDetailsIcon;
    public TextView tvPlateDetailsPlateName;
    public TextView tvPlateDetailsPlateNum;
    public TextView tvPlateDetailsFocusNum;
    public TextView tvPlateDetailsAuthorName;
    public TextView tvPlateDetauksFocus;
    public ListView topPlateDetailsZhiDing;
    public CollapsingToolbarLayout collapsingToolbarLayout;
    public LinearLayout detailBack;
    public ImageView imageDetailsMore;
    public LinearLayout detailMore;
    public ImageView PlateDetailsAdPic;
    public ImageView PlateDetailsClose;
    public RelativeLayout PlateDetailsAd;
    public TabLayout topTitleTabLayout;
    public ViewPager tooic_content_viewPager;
    public static AppBarLayout appBarLayout;
    int firstId,secondId;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_plate_detial;
    }

    @Override
    public void initData() {
        setVpData();
        setTooBarData();
        setAdData();
        setPlateMessageData();
        setAtTopListData();
        setTabLayoutData();
    }

    private void setTabLayoutData() {

        tooic_content_viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(topTitleTabLayout));
        topTitleTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(tooic_content_viewPager));
    }

    private void setTooBarData() {
        detailBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        imageDetailsMore.setImageResource(R.mipmap.lt_shangchuan);
        detailMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

    }

    private void setAdData() {
        PlateDetailsClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PlateDetailsAd.setVisibility(View.GONE);
            }
        });
    }

    private void setPlateMessageData() {
        tvPlateDetauksFocus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LogUtils.e("关注");
            }
        });
    }

    private void setAtTopListData() {
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            strings.add("瞧不上那东海的龙宫 我胡吃海塞");
        }
        topPlateDetailsZhiDing.setAdapter(new ArrayAdapter<String>(this, R.layout.item_attop_list, R.id.text_zhiding, strings));
        topPlateDetailsZhiDing.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                LogUtils.e("置顶点击" + i);
            }
        });
        Tool.setListViewHeightBasedOnChildren(topPlateDetailsZhiDing);
    }

    private void setVpData() {
        Intent intent = getIntent();
        int firstID = intent.getIntExtra("firstID", -1);
        int secondID = intent.getIntExtra("secondID", -1);
        if(firstID==-1||secondID==-1){
            LogUtils.e("数据加载失败");
            finish();
            return;
        }else {
            this.firstId=firstID;
            this.secondId=secondID;

        }

        final ArrayList<PlateSortDetailFragment> my_fragments = new ArrayList<>();
        PlateSortDetailFragment e1 = new PlateSortDetailFragment();
        e1.setType(1,firstID,secondID);
        my_fragments.add(e1);
        PlateSortDetailFragment e = new PlateSortDetailFragment();
        e.setType(2,firstID,secondID);
        my_fragments.add(e);
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {

                return my_fragments.get(position);
            }

            @Override
            public int getCount() {
                return 2;
            }
        };

        tooic_content_viewPager.setAdapter(adapter);

    }

    @Override
    public void initView() {
        imagePlateDetailsIcon = (ImageView) findViewById(R.id.image_PlateDetails_Icon);
        tvPlateDetailsPlateName = (TextView) findViewById(R.id.tv_PlateDetails_PlateName);
        tvPlateDetailsPlateNum = (TextView) findViewById(R.id.tv_PlateDetails_PlateNum);
        tvPlateDetailsFocusNum = (TextView) findViewById(R.id.tv_PlateDetails_FocusNum);
        tvPlateDetailsAuthorName = (TextView) findViewById(R.id.tv_PlateDetails_AuthorName);
        tvPlateDetauksFocus = (TextView) findViewById(R.id.tv_PlateDetauks_Focus);
        topPlateDetailsZhiDing = (ListView) findViewById(R.id.top_PlateDetails_ZhiDing);
        collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar_layout);
        appBarLayout = (AppBarLayout) findViewById(R.id.appBarLayout);
        topTitleTabLayout = (TabLayout) findViewById(R.id.top_Title_TabLayout);
        tooic_content_viewPager = (ViewPager) findViewById(R.id.tooic_content_viewPager);
        detailBack = (LinearLayout) findViewById(R.id.detail_Back);
        imageDetailsMore = (ImageView) findViewById(R.id.image_Details_More);
        detailMore = (LinearLayout) findViewById(R.id.detail_More);
        PlateDetailsAdPic = (ImageView) findViewById(R.id.PlateDetails_AdPic);
        PlateDetailsClose = (ImageView) findViewById(R.id.PlateDetails_Close);
        PlateDetailsAd = (RelativeLayout) findViewById(R.id.PlateDetails_Ad);
    }
}
